#pragma once

class CGRect
{
public:
	static CRect Center(const CRect &container, const CRect &object)
	{
		CPoint point;
		point.x = container.left + (container.Width() - object.Width()) / 2;
		point.y = container.top + (container.Height() - object.Height()) / 2;
		return CRect(point, object.Size());
	}

	static CRect LetterBox(const CRect &container, const CRect &object)
	{
		double containerRadio = container.Width() / static_cast<double>(container.Height());
		double objectRadio = object.Width() / static_cast<double>(object.Height());
		LONG targetWidth, targetHeight, targetX, targetY;
		if (containerRadio >= objectRadio)
		{
			targetHeight = container.Height();
			targetWidth = object.Width() * targetHeight / object.Height();
		}
		else
		{
			targetWidth = container.Width();
			targetHeight = object.Height() * targetWidth / object.Width();
		}
		targetX = container.left + (container.Width() - targetWidth) / 2;
		targetY = container.top + (container.Height() - targetHeight) / 2;
		return CRect(CPoint(targetX, targetY), CSize(targetWidth, targetHeight));
	}
};